package com.tomowork.dao.impl;

import com.tomowork.dao.IDeptDAO;
import com.tomowork.entity.Dept;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

@Repository
public class DeptDAOImpl implements IDeptDAO {
    @PersistenceContext
    private EntityManager entityManager ;
    @Override
    public void doCreate(Dept dept) {
        entityManager.persist(dept); ;
    }

    @Override
    public List<Dept> findAll() {
        String jpql = "from Dept" ;
        Query query = entityManager.createQuery(jpql);
        List<Dept> deptList = query.getResultList();
        return deptList;
    }
}
